import traceback

import pyautogui
import requests

from asset.constants import *

TIMEOUT=5

def convert_version_info(string:str)->"tuple[int,int,int]":return tuple(map(int,string.split('.')))
try:
    url=DOGSOCUTEURL+"game/Elivo/latest.txt"
    print("Connecting to "+url)
    r = requests.get(url,timeout=TIMEOUT)
    latest_version_string=r.content.decode()
    latest_version_info=convert_version_info(latest_version_string)
    if game_version<latest_version_info:
        pyautogui.alert("You are using version %s , while stable version %s is avaliable.\n Please consider downloading the latest version by going to dogsocute.icu ."%(version_string,latest_version_string),"Version Checker")
    else:
        if len(game_version) < 4:print("""Thanks for using the version %s of Elivo!"""%version_string)
        else:print("This version is %s , you may download the latest stable version %s."%(version_string,latest_version_string))
except:print("Checker failure.");traceback.print_exc()
